<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String imgSrc = basePath + "resources/images/noImage.jpg";
    session.setAttribute("imgSrc", imgSrc);
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../resources/inc/head.jsp" %>
</head>
<body>
<expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段" widthClass="full-width-85"/>

<div class="layui-form common-form" lay-filter="layuiadmin-form-contentFriendlyLink" id="layuiadmin-form-contentFriendlyLink"
     style="padding: 20px;">


    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline">
            <input type="hidden" name="id" value="${contentNotification.id}">
            <input type="text" name="name" lay-verify="required" value="${contentNotification.name}"
                   placeholder="请输入名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="display:inline;">
        <label class="layui-form-label">正文</label>
        <div class="layui-input-inline">
            <expect-x:UEditor uEditorId="content" uEditorContent="${contentNotification.content}" />
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>
</div>

<%@include file="../../../resources/inc/footer.jsp" %>

<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form
    })

    function createSubmit() {
        var userId = "${sessionScope.permissionUser.id}";
        var layer=layui.layer;
        var submitID = 'LAY-submit';
        layui.form.on('submit('+ submitID +')', function(data){
            var formData = data.field;
            formData.content = UE.getEditor('content').getContent()
            formData.userId = userId
            if(formData.id==""||formData.id==null){
                delete formData["id"];
                $.ajax({
                    url:'<%=basePath%>manager/contentNotification/create.html',
                    type:"POST",
                    data:formData,
                    dataType:"JSON",
                    success:function (data) {
                        layer.closeAll('loading');
                        if(data.success){
                            layer.msg("创建成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            },1000);
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }else{
                $.ajax({
                    url:"<%=basePath%>manager/contentNotification/update/"+formData.id+".html",
                    type:"POST",
                    data:formData,
                    dataType:"JSON",
                    success:function (data) {
                        layer.closeAll('loading');
                        if(data.success){
                            layer.msg("修改成功,1秒后跳转");
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            },1000);
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        })
        $("#"+submitID).trigger('click');
    }
</script>
</body>
</html>